/* 
 * File:   main.cpp
 * Author: alrojas
 *
 * Created on 8 de marzo de 2014, 19:08
 */

//#include "ConcaveHull.h"
#include "NFP.h"
#include "ConcaveHull.h"

/*
 * 
 */
int main(int argc, char** argv){
    
    
    NFP nfp;
    //nfp.Test();
    
    ConcaveHull ch;
    
    Mat background = Mat::zeros(600,900,CV_8UC3);
    
    vector < Point > cA;
    vector < Point > B;
    vector < Point > cB;

    for(uint i = 0; i < 10; i++){
        Point p(rng.uniform(50,250),rng.uniform(50,250));
        cA.push_back(p);
    }
    
    for(uint j = 0; j < 10; j++){
        Point p(rng.uniform(50,250),rng.uniform(50,250));
        cB.push_back(p);
    }
    
    ch.convexHull(cA,cA);
    ch.convexHull(cB,cB);  
    
    //nfp.DrawPolygon(background,cA,Point(20,20));
    //nfp.DrawPolygon(background,cB,Point(20,300));  
    
    vector < vector < Point > > ps;
    ps.push_back(cA);
    ps.push_back(cB);
    
    vector < Point > g;
    
    //nfp.GhoshNoFitPolygon(ps,g);
    nfp.CuninghameGreenNoFitPolygon(ps,g);
    
    vector < Point > g2 = g;
    std::sort(g2.begin(),g2.end(),utils::myobject1);
    nfp.Traslation(g,Point(450,150),g2[0],g);
    
    vector < Point > cA2 = cA;
    std::sort(cA2.begin(),cA2.end(),utils::myobject1);
    nfp.Traslation(cA,Point(450,150),cA2[0],cA);

    vector < vector < Point > > pps;
    pps.push_back(g);
    pps.push_back(cA);

    vector < Point > cB2 = cB;
    std::sort(cB2.begin(),cB2.end(),utils::myobject2);
     
    for(uint j = 0; j < g.size(); j++){
        vector < Point > cb;
        nfp.Traslation(cB,g[j],cB2[0],cb);
        pps.push_back(cb);
    }
    
    
    drawContours(background,pps,0,cvScalar(255,0,0),1);
    drawContours(background,pps,1,cvScalar(0,255,0),1);
    for(uint i = 2; i < pps.size(); i++){
        drawContours(background,pps,i,cvScalar(0,0,255),1);
    }
    
    //nfp.DrawPolygon(background,g,Point(300,20));
    
    imwrite("test.JPG",background);
    
    imshow("",background);
    cvWaitKey();
    
    
    return 0;
}

